package test.davidlauzon.activerecord;

import java.sql.SQLException;
import java.util.Map;

import davidlauzon.activerecord.ActiveRecord;
import davidlauzon.activerecord.nodes.Table;
import davidlauzon.activerecord.nodes.field.Field;
import davidlauzon.activerecord.nodes.field.FloatField;
import davidlauzon.activerecord.nodes.field.IntegerField;
import davidlauzon.activerecord.nodes.field.StringField;

public class MyProduct extends ActiveRecord
{
    public static final Field ID        = new IntegerField("id", true);
    public static final Field NAME      = new StringField("name", false);
    public static final Field PRICE     = new FloatField("price", false);
    public static final Field PERSON_ID = new IntegerField("person_id", false);
    
    public static final Field[] FIELDS = {ID,NAME,PRICE,PERSON_ID};
    
    @Override public Table        getTable()          { return AndroidDB.PRODUCTS_TABLE; }
    @Override public Field[]      getFields()         { return FIELDS; }
    @Override public ActiveRecord getStaticInstance() { return _static_instance; }
    
    static private Class __klass = MyProduct.class;
    static public MyProduct build( Map<Field, Object> attributes)                              { return (MyProduct)build(__klass, attributes); }
    static public MyProduct create(Map<Field, Object> attributes) throws SQLException          { return (MyProduct)create(__klass, attributes); }
    static public boolean update(long id, Map<Field, Object> attributes) throws SQLException { return update(__klass, id, attributes); }
    static public boolean delete(long id) throws SQLException                                { return delete(__klass, id); }
    
    // MUST BE INSTANCIATED AFTER ALL OTHER VARIABLES
    static protected final MyProduct _static_instance = new MyProduct();
}